

/*
 *  Test objects
 */
var TEST_PROJECT_FILE = "../project.silobox.js";

var TEST_PROJECT_SETTINGS = {
	title: "Test Project",
	scripts: [
		"../normal-looping.silobox.js",
		"../backwards-looping.silobox.js",
		"../bonkers-looping.silobox.js"
	]
};

var ARGS_1_PRESTART = {	
};
var ARGS_2_START = {
	phase: "start",
	project: TEST_PROJECT_FILE
};
var ARGS_3_RUNNING = {
	phase: "running",
	step: 1,
	project: TEST_PROJECT_FILE
};
var ARGS_4_RUNNING = {
	phase: "running",
	step: 2,
	project: TEST_PROJECT_FILE
};
var ARGS_5_RUNNING = {
	phase: "running",
	step: 3,
	project: TEST_PROJECT_FILE
};
var ARGS_6_FINISHED = {
	phase: "finished",
	project: TEST_PROJECT_FILE
};

var SAMPLE_TEST_1 = {
	
	title: "Script One",
	
	setup: function() {
	
	},
	code: function() {
		
		
		
	},
	cleanup: function() {
		
	}
	
};






module("SBHead");

test("SBHead", function() {

	equals($("head")[0], SBHead(), "<head /> not properly found.");
	
	SB_cache_head = ["monkey"];
	
	// test cache too - calling it again should return the cache
	equals(SBHead()[0], "monkey", "<head /> not properly found.");
	
	// clear it for next time
	SB_cache_head = null;
	
	expect(2);
	
});



module("SBLoadScript");

var SOME_VARIABLE = null;

test("SBLoadScript", function(){
	
	ok(SOME_VARIABLE == null, "SOME_VARIABLE should be null.");
	
	// include a script that will change "SOME_VARIABLE"
	SBLoadScript("tests/helpers/modify_SOME_VARIABLE.js")
	
	expect(1);
	stop();
	
});
test("SBLoadScript (after)", function(){

	equals(SOME_VARIABLE, "Modified", "SOME_VARIABLE should have been modified.")
	
	expect(1);
	
});


module("SBArgs");

test("SBArgs", function() {

	var args = SBArgs();
	
	SB_cache_args = "Monkey";
	
	equals("Monkey", SBArgs(), "SBArgs() should use cache.")
	
});


module("SBProject");

test("Function", function() {

	var options = TEST_PROJECT_SETTINGS;
	
	ok(SBProjectSettings == null, "SBProjectSettings should start null.")
	
	SBProject(options);
	
	ok(SBProjectSettings != null, "SBProjectSettings should not be null")
	
	equals(SBProjectSettings, options, "Argument passed to SBProject should be saved in SBProjectSettings");
	
	expect(3);

});


module("SBProjectSteps");

test("Getting project steps", function(){
	
	// use the test project settings (see top)
	SBProjectSettings = TEST_PROJECT_SETTINGS;
	
	equals(SBProjectSteps(), 3, "There are 3 scripts in the TEST_PROJECT_SETTINGS.")
	
	SBProjectSettings = { title: "Scriptless" };
	
	equals(SBProjectSteps(), 0, "There are 0 scripts in the project settings.  .scripts is undefined so zero should be returned..")
	
});



module("SBIsFinished");

test("SBIsFinished knows when there are no more scripts to test", function(){
	
	// use the test project settings (see top)
	SBProjectSettings = TEST_PROJECT_SETTINGS;
	
	equals(SBIsFinished(1), false, "SBIsFinished shouldn't think it is finished.");
	equals(SBIsFinished(2), false, "SBIsFinished shouldn't think it is finished.");
	equals(SBIsFinished(3), true, "SBIsFinished should think it is finished.");
	
	expect(3);
	
});


module("SBPhaseToIndex");

test("SBPhaseToIndex", function(){
	
	equals(0, SBPhaseToIndex(""), "\"\"");
	equals(1, SBPhaseToIndex("start"), "start");
	equals(2, SBPhaseToIndex("running"), "running");
	equals(2, SBPhaseToIndex("running"), "running");
	equals(3, SBPhaseToIndex("finished"), "finished");
	
});


module("SBIndexToPhase");

test("SBIndexToPhase", function() {
	
	equals("prestart", SBIndexToPhase(0));
	equals("start", SBIndexToPhase(1));
	equals("running", SBIndexToPhase(2));
	equals("finished", SBIndexToPhase(3));
	
});


module("SBShouldRunTest");

test("SBShouldRunTest knows when tests should be performed", function(){
	
	// prestart
	equals(SBShouldRunTest(ARGS_1_PRESTART), false, "[1] should be false.");
	equals(SBShouldRunTest(ARGS_2_START), false, "[2] should be false.");
	equals(SBShouldRunTest(ARGS_3_RUNNING), true, "[3] should be true.");
	equals(SBShouldRunTest(ARGS_4_RUNNING), true, "[4] should be true.");
	equals(SBShouldRunTest(ARGS_5_RUNNING), true, "[5] should be true.");
	equals(SBShouldRunTest(ARGS_6_FINISHED), false, "[6] should be false.");
	
});


module("SBArgsToUrl");
test("SBArgsToUrl knows how to turn objects into strings", function(){
	
	equals(SBArgsToUrl({  }), "");
	equals(SBArgsToUrl({ one: 1 }), "one=1");
	equals(SBArgsToUrl({ one: 1, two: 2 }), "one=1&two=2");
	equals(SBArgsToUrl({ one: 1, two: 2, three: 3 }), "one=1&two=2&three=3");
	
});


module("SBGetNextArgs");

test("SBGetNextArgs should know the next state", function(){

	// use the test project settings (see top)
	SBProjectSettings = TEST_PROJECT_SETTINGS;
	
	equals(SBGetNextArgs(ARGS_1_PRESTART).phase, "start");
	//equals(SBGetNextArgs(ARGS_1_PRESTART).project, TEST_PROJECT_FILE);
	
	equals(SBGetNextArgs(ARGS_2_START).phase, "running");
	equals(SBGetNextArgs(ARGS_2_START).project, TEST_PROJECT_FILE);
	equals(SBGetNextArgs(ARGS_2_START).file, TEST_PROJECT_SETTINGS.scripts[0]);
	equals(SBGetNextArgs(ARGS_2_START).step, 1, "step==1");
	
	equals(SBGetNextArgs(ARGS_3_RUNNING).phase, "running");
	equals(SBGetNextArgs(ARGS_3_RUNNING).project, TEST_PROJECT_FILE);
	equals(SBGetNextArgs(ARGS_3_RUNNING).file, TEST_PROJECT_SETTINGS.scripts[1]);
	equals(SBGetNextArgs(ARGS_3_RUNNING).step, 2, "step==2");
	
	equals(SBGetNextArgs(ARGS_4_RUNNING).phase, "running");
	equals(SBGetNextArgs(ARGS_4_RUNNING).project, TEST_PROJECT_FILE);
	equals(SBGetNextArgs(ARGS_4_RUNNING).file, TEST_PROJECT_SETTINGS.scripts[2]);
	equals(SBGetNextArgs(ARGS_4_RUNNING).step, 3, "step==3");
	
	equals(SBGetNextArgs(ARGS_5_RUNNING).phase, "finished");
	equals(SBGetNextArgs(ARGS_5_RUNNING).project, TEST_PROJECT_FILE);
	
	/*
	equals(SBGetNextRedirectUrl(ARGS_1_PRESTART), "phase=start&project=../project.silobox.js");
	equals(SBGetNextRedirectUrl(ARGS_2_START), "phase=running&project=");
	equals(SBGetNextRedirectUrl(ARGS_3_RUNNING), "phase=running&project=../project.silobox.js");
	equals(SBGetNextRedirectUrl(ARGS_4_RUNNING), "phase=running&project=../project.silobox.js");
	equals(SBGetNextRedirectUrl(ARGS_5_RUNNING), "phase=finished&project=../project.silobox.js");
	*/
	// this doesn't make sense
	//equals(SBGetNextRedirectUrl(ARGS_6_FINISHED), "");
	
	expect(15)
	
});


module("SBNeedsProjectFile");

test("SBNeedsProjectFile knows when a project file is needed", function(){
	
	equals(SBNeedsProjectFile(ARGS_1_PRESTART), true);
	equals(SBNeedsProjectFile(ARGS_2_START), false);
	equals(SBNeedsProjectFile(ARGS_3_RUNNING), false);
	equals(SBNeedsProjectFile(ARGS_4_RUNNING), false);
	equals(SBNeedsProjectFile(ARGS_5_RUNNING), false);
	equals(SBNeedsProjectFile(ARGS_6_FINISHED), false);
	
});


module("SBGetPercentageComplete");

test("SBGetPercentageComplete should get the right percentages", function(){
	
	equals(SBGetPercentageComplete(ARGS_1_PRESTART), 0);
	equals(SBGetPercentageComplete(ARGS_2_START), 0);
	equals(SBGetPercentageComplete(ARGS_3_RUNNING), 20);
	equals(SBGetPercentageComplete(ARGS_4_RUNNING), 40);
	equals(SBGetPercentageComplete(ARGS_5_RUNNING), 60);
	equals(SBGetPercentageComplete(ARGS_6_FINISHED), 100);
	
});


module("SBGetProgressStatus");

test("SBGetProgressStatus talks nice things", function(){
	
	equals(SBGetProgressStatus(ARGS_1_PRESTART), 	"Not started");
	equals(SBGetProgressStatus(ARGS_2_START), 		"Starting...");
	equals(SBGetProgressStatus(ARGS_3_RUNNING, SAMPLE_TEST_1), 	"Benchmarking " + SAMPLE_TEST_1.title);
	equals(SBGetProgressStatus(ARGS_4_RUNNING, SAMPLE_TEST_1), 	"Benchmarking " + SAMPLE_TEST_1.title);
	equals(SBGetProgressStatus(ARGS_5_RUNNING, SAMPLE_TEST_1), 	"Benchmarking " + SAMPLE_TEST_1.title);
	equals(SBGetProgressStatus(ARGS_6_FINISHED), 	"Finished.");
	
});

